<%--
  Created by IntelliJ IDEA.
  User: jasonmarslyon
  Date: 2022/11/1
  Time: 16:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<div class="header_i">
  <!--logo-->
  <a href="#">
    <div class="logo">
      <span>LinkedChat</span>
    </div>
  </a>
  <!--nav-->
  <div class="nav">
    <ul >
      <li class="menu_item"><a href="${pageContext.request.contextPath}/index.jsp">首页</a></li>
      <li class="menu_item"><a href="${pageContext.request.contextPath}/public/Job/SearchJob.jsp">职位</a></li>
      <li class="menu_item"><a href="">校园</a></li>
      <li class="menu_item"><a href="">海归</a></li>
      <li class="menu_item"><a href="${pageContext.request.contextPath}/public/Company/CompanyHomePage.jsp">公司</a></li>
      <li class="menu_item"><a href="">APP</a></li>
      <li class="menu_item"><a href="">咨询</a></li>
      <li class="menu_item"><a href="">百科</a></li>
    </ul>
  </div>

  <!--登录区域  -->
  <div class="login_info" style="display: block">
    <div class="head_msg">
      <a href="" class="drop_trigger">
        <ul >
          <li class="menu_item">上传简历</li>
          <li class="menu_item">我要找工作</li>
        </ul>
      </a>

    </div>
    <div class="head_user">
      <a href="${pageContext.request.contextPath}/public/Person/Login.jsp" class="loginBtn usernameorlogin" >登陆</a>
      <a href="${pageContext.request.contextPath}/public/Person/Register.jsp" class="loginBtn">注册</a>
    </div>
  </div>
  <div class="login_info1" style="display: none">
    <ul >
      <li class="menu_item">
        <script>
          $.ajax({
            async:false,
            type: "get",
            url: "${pageContext.request.contextPath}/chatHistory/showImg",
            success: function (res) {
              console.log("展示小红点"+res)
            }
          })
        </script>
        <a href="#" class="header_message" id="header_message1">消息
          <span class = "message_chat_num" style="display: none" ><img id="message_chat_num" src='/link/static/img/redPoint.png' style = 'height:30px;width:30px;
          position: absolute;margin-left: -15px'/>
          <input type="hidden" value="${sessionScope.loginPerson.personName}" id="header_message">
          </span>
        </a>
      </li>
      <li class="menu_item">
        <a href="${pageContext.request.contextPath}/public/Person/CVManage.jsp" class="header_cv">简历</a>
      </li>
      <li class="header_figure menu_item">
        <a href="#" class="header_username">
          <span class="un_text" style="margin-left: 40px"> </span>
          <img src="https://img.bosszhipin.com/boss/avatar/avatar_14.png" alt="">
        </a>
        <div class="dropdown">
          <a href="${pageContext.request.contextPath}/public/Person/PersonCenter.jsp" class="person_center">
            个人中心
            <span>推荐职位、编辑在线简历</span>
          </a>
          <a href="${pageContext.request.contextPath}/jsp/backStageLogin.jsp" class="change_recruit">切换为招聘者</a>
          <a href="javascript:void(0)" class="logout">退出登陆</a>
        </div>
      </li>
    </ul>
  </div>
</div>







<script>



  //登陆信息
  var token = localStorage.getItem("token");
  if (token != null){

    /*loadIndexData();*/

    /*function loadIndexData(){*/
    console.log("=====登陆信息显示======");
    /*var token = localStorage.getItem("token");*///获得在登录界面生成的 token
    console.log("index获得的token-----:" + token);

    $.ajax({
      type: "get",
      url: "${pageContext.request.contextPath}/loginData",//与IndexController的 testIndex方法实现前后端数据交互
      headers:{"token": token},
      success:function (result){
        console.log(result);
        var data = result.data;
        console.log("=================================================================="+data);

        var loginUser = data.loginPerson;
        console.log("当前用户 === ："+loginUser.personName)
        if (loginUser != null){
          $(".login_info").css("display","none");
          $(".login_info1").css("display","block");
          $(".login_info1 .header_figure .header_username .un_text").text(loginUser.personName);
          $(".login_info1 .header_figure .header_username .un_text").attr("href","person" + loginUser.personId);

        }
      }

    })
  }

  $("#header_message1").click(function (){
    var loginPersonName = $("#header_message").val();
    if(loginPersonName === ""){
      alert("你的消息用户名已下线，从新登录吧赶紧！")
      location.href = "${pageContext.request.contextPath}/public/Person/Login.jsp";
    }else {
      location.href = "${pageContext.request.contextPath}/static/chatMain.jsp";
    }
  })

  //用户退出登陆
  $(".logout").click(function () {
    var token = localStorage.getItem("token");
    console.log("即将退出的token:" + token);
    if (token != null){
      localStorage.removeItem("token");
      location.reload();
    }
  })

</script>







